package com.example.hencoderdemo.animlesson;

import android.animation.Animator;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ImageView;

import androidx.annotation.Nullable;

import com.example.hencoderdemo.Common.Utils;
import com.example.hencoderdemo.R;
import com.example.hencoderdemo.lessonView.CaneraView;

public class AnimActivity extends Activity {
    private CaneraView view;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_anim);
        view = findViewById(R.id.view);
//        view.animate()
//                .translationX(Utils.dp2px(200))
//                .translationY(Utils.dp2px(200))
//                .alpha(0.5f)
//                .rotation(200)
//                .setStartDelay(200)
//                .start();



//        ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(view,"radius",Utils.dp2px(150));
//        objectAnimator.setStartDelay(1500);
//        objectAnimator.start();


        //翻页效果

        //1，底部折起
        ObjectAnimator objectAnimator_bottonm = ObjectAnimator.ofInt(view,"cameraDegree_bottom",45);
        //2,旋转
        ObjectAnimator objectAnimator_rotate = ObjectAnimator.ofInt(view,"rotateDegree",360);
        objectAnimator_rotate.setDuration(1500);

        //3，顶部折起来
        ObjectAnimator objectAnimator_up = ObjectAnimator.ofInt(view,"cameraDegree_up",-45);
        //4,再放下
        ObjectAnimator objectAnimator_both = ObjectAnimator.ofInt(view,"cameraDegree_both",0);
        objectAnimator_both.setDuration(1000);
        //5，切割

        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.playSequentially(objectAnimator_bottonm, objectAnimator_rotate,objectAnimator_up,objectAnimator_both);
        animatorSet.setStartDelay(1500);
        animatorSet.start();
        animatorSet.addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {

            }

            @Override
            public void onAnimationEnd(Animator animation) {
                view.setClip(true);
            }

            @Override
            public void onAnimationCancel(Animator animation) {

            }

            @Override
            public void onAnimationRepeat(Animator animation) {

            }
        });

    }
}
